package com.jk.smartelderlycare.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jk.smartelderlycare.dao.SysDynamicsMapper;
import com.jk.smartelderlycare.dto.SysDynamics;
import com.jk.smartelderlycare.pojo.PagedResponse;
import com.jk.smartelderlycare.service.SysDynamicsService;
import com.jk.smartelderlycare.utils.PaginationUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author hhk
 * @version 1.0
 * @ClassName SysDynamicsServiceImpl
 * @program: smart-elderly-care
 * @description: TODO
 * @date 2024/11/19 20:24
 */
@Service
public class SysDynamicsServiceImpl implements SysDynamicsService {

    @Autowired
    private SysDynamicsMapper sysDynamicsMapper;
    /**
     * @description: 分页查询
     * @param: [sysDynamics, pageNum, pageSize]
     * @return: com.jk.smartelderlycare.pojo.PagedResponse<com.jk.smartelderlycare.dto.SysDynamics>
     * @author hhk
     * @date: 2024/11/19 20:25
     */
    @Override
    public PagedResponse<SysDynamics> findSysDynamicsPaginationList(SysDynamics sysDynamics, Integer pageNum, Integer pageSize) {
        Page<SysDynamics> page = new Page<>(pageNum,pageSize);
        QueryWrapper<SysDynamics> queryWrapper = new QueryWrapper<>();
        if(null != sysDynamics.getDynamicsContent() && !"".equals(sysDynamics.getDynamicsContent())){
            queryWrapper.like("dynamics_content",sysDynamics.getDynamicsContent());
        }
        if (null != sysDynamics.getStartDate() && !"".equals(sysDynamics.getStartDate())){
            queryWrapper.ge("modify_date",sysDynamics.getStartDate());
        }
        if (null != sysDynamics.getEndDate() && !"".equals(sysDynamics.getEndDate())){
            queryWrapper.le("modify_date",sysDynamics.getEndDate());
        }
        Page<SysDynamics> sysDynamicsPage = sysDynamicsMapper.selectPage(page, queryWrapper);

        return PaginationUtil.getPagedResponse(sysDynamicsPage.getRecords(),pageNum,pageSize,sysDynamicsPage.getTotal());
    }
    /**
     * @description: 新增
     * @param: [sysDynamics]
     * @return: void
     * @author hhk
     * @date: 2024/11/19 20:31
     */
    @Override
    public void addSysDynamics(SysDynamics sysDynamics) {
        sysDynamicsMapper.insert(sysDynamics);
    }
    /**
     * @description: 根据id删除数据
     * @param: [dynamicsId]
     * @return: void
     * @author hhk
     * @date: 2024/11/19 20:31
     */
    @Override
    public void deleteSysDynamicsById(Long dynamicsId) {
        sysDynamicsMapper.deleteById(dynamicsId);
    }
    /**
     * @description: 根据id回显
     * @param: [dynamicsId]
     * @return: com.jk.smartelderlycare.dto.SysDynamics
     * @author hhk
     * @date: 2024/11/19 20:32
     */
    @Override
    public SysDynamics findSysDynamicsById(Long dynamicsId) {
        return sysDynamicsMapper.selectById(dynamicsId);
    }
    /**
     * @description: 修改
     * @param: [sysDynamics]
     * @return: void
     * @author hhk
     * @date: 2024/11/19 20:32
     */
    @Override
    public void updateSysDynamics(SysDynamics sysDynamics) {
        sysDynamicsMapper.updateById(sysDynamics);
    }
    /**
     * @description: 状态修改
     * @param: [sysDynamics]
     * @return: void
     * @author hhk
     * @date: 2024/11/19 20:32
     */
    @Override
    public void updateStatusById(SysDynamics sysDynamics) {
        sysDynamicsMapper.updateStatusById(sysDynamics);
    }
    /**
     * @description: 批量删除
     * @param: [ids]
     * @return: void
     * @author hhk
     * @date: 2024/11/19 20:33
     */
    @Override
    public void deleteSysDynamicsByIds(List<Long> ids) {
        sysDynamicsMapper.deleteBatchIds(ids);
    }
}
